﻿using System;
using System.Data;

namespace HungFire.Net5.Filter
{
    [AttributeUsage(AttributeTargets.Method | AttributeTargets.Class)]
    public class TimeJobAttribute : Attribute
    {
        public string CronExpression { get; set; }
        public string JobName { get; set; }

        public bool EnableStatus { get; set; }=true;
        /// <summary>
        /// Job类型
        /// </summary>
        public JobTypeEnum JobType { get; set; } = JobTypeEnum.Cron;
        /// <summary>
        /// 延时启动时间,格式为yyyyMMdd HH:mm:ss
        /// </summary>
        public string DelayedStartTime { get; set; }

        public TimeJobAttribute(string jobName)
        {
            JobName = jobName;
        }
        public TimeJobAttribute(string jobName, string cronExp)
        {
            JobName = jobName;
            CronExpression = cronExp;
        }

        public TimeJobAttribute(string jobName, string cronExp,bool enableStatus)
        {
            JobName = jobName;
            CronExpression = cronExp;
            EnableStatus = enableStatus;
        }
        public TimeJobAttribute(string jobName, string cronExp, JobTypeEnum jobType)
        {
            JobName = jobName;
            CronExpression = cronExp;
            JobType = jobType;
        }

        public TimeJobAttribute(string jobName, string cronExp, JobTypeEnum jobType, string delayedTime)
        {
            JobName = jobName;
            CronExpression = cronExp;
            JobType = jobType;
            DelayedStartTime = delayedTime;
        }
        /// <summary>
        /// 执行job类型
        /// </summary>
        public enum JobTypeEnum
        {
            /// <summary>
            /// 后台排队执行，执行一次
            /// </summary>
            Enqueue = 1,
            /// <summary>
            /// 延时执行，在启动后多少分钟执行，此方式需填写DelayedStartTime，且只执行一次
            /// </summary>
            Schedule = 2,
            /// <summary>
            /// 使用Cron表达式重复执行
            /// </summary>
            Cron = 3
        }

    }
}
